package org.wdcode.core.concurrent;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * 获得同步线程锁的工厂类
 * @author WD
 * @since JDK6
 * @version 1.0 2009-12-18
 */
public final class LockFactory {
	/**
	 * 获得线程锁
	 * @return 线程锁
	 */
	public final static Lock getLock() {
		return new ReentrantLock();
	}

	/**
	 * 获得读锁
	 * @return 读锁
	 */
	public final static Lock getReadLock() {
		return new ReentrantReadWriteLock().readLock();
	}

	/**
	 * 获得写锁
	 * @return 写锁
	 */
	public final static Lock getWriteLock() {
		return new ReentrantReadWriteLock().writeLock();
	}

	/**
	 * 获得读写锁
	 * @return 读写锁
	 */
	public final static ReadWriteLock getReadWriteLock() {
		return new ReentrantReadWriteLock();
	}

	/**
	 * 私有构造 防止外部实例化
	 */
	private LockFactory() {}
}
